﻿using System;
using System.Windows.Controls;
using Amercom.Silverlight.Lib;
using Amercom.Silverlight.Controls;
using Amercom.Silverlight.Helpers.PanoramaCube;

namespace Amercom.Silverlight
{

    /*
     ****************************
     * Panorama Cube, Silverlight version
     * By Martijn Croezen and Rob Houweling
     * This is a proof of concept version and is not at all optimized or cleaned up!
     * 
     * martijn@amercom.nl / http://whizzkid74.blogspot.com
     * rob@amercom.nl / http://web-snippets.blogspot.com
     * (c) 2008 Amercom B.V. http://www.amercom.nl
     * **************************
     * 3d cube routines where used from Einar Ingebrigtsen 
     * http://www.dolittle.com/blogs/einar/default.aspx
     */
    public partial class Page : UserControl
    {
        
        public Page()
        {
            InitializeComponent();

            this.Loaded += new System.Windows.RoutedEventHandler(Page_Loaded);
            
            
        }

        void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            PanoramaImageList panoramaImages = new PanoramaImageList();
            PanoramaCube cube;

            panoramaImages.FrontFaceImage = new Uri("images/pano2_f.jpg", UriKind.Relative);
            panoramaImages.RightFaceImage = new Uri("images/pano2_r.jpg", UriKind.Relative);
            panoramaImages.BackFaceImage = new Uri("images/pano2_b.jpg", UriKind.Relative);
            panoramaImages.LeftFaceImage = new Uri("images/pano2_l.jpg", UriKind.Relative);
            panoramaImages.TopFaceImage = new Uri("images/pano2_u.jpg", UriKind.Relative);
            panoramaImages.BottomFaceImage = new Uri("images/pano2_d.jpg", UriKind.Relative);
            

            cube = new PanoramaCube(this, PanoramaCubeCanvas, panoramaImages, 30, 7,1024);
            cube.Width = 800;
            cube.Height = 600;
            cube.DebugEnabled = true;

            LayoutRoot.Children.Add(cube);
            // -90
            //  |
            //  |    up
            //  |
            //  ------- 0
            //  |
            //  |  down
            //  |
            //  90
            // 
            // rotation around X axis will make the camera look up (0 to -90) or down (0 to 90)
            // rotation around Y axis will make the camera look right (values larger than 0)  and left (values smaller than 0)
            cube.SetRotation(10, -7);
            cube.SetZoom(23);
            cube.EnableRendermodeSwitch = true;

            DebugLogger.enabled = true;
            DebugLogger.enableOutputLog(true);
            DebugLogger.debugWrite("rotation : " + cube.GetRotation().ToString());
            DebugLogger.debugWrite("rotation : " + cube.GetZoom().ToString());
        }
    }
}
